package org.dromara.xhlj.crud.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import org.dromara.common.satoken.utils.LoginHelper;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.xhlj.domain.vo.XhljProductFeedbackVo;
import org.dromara.xhlj.domain.query.XhljProductFeedbackQuery;
import org.dromara.xhlj.domain.bo.XhljProductFeedbackBo;
import org.dromara.xhlj.crud.service.IXhljProductFeedbackCrudService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * xhlj-crud-展商产品反馈留言
 *
 * @author yf
 * @date 2024-07-28
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/xhlj/productFeedback")
public class XhljProductFeedbackCrudController extends BaseController {

    private final IXhljProductFeedbackCrudService xhljProductFeedbackService;

    /**
     * 分页查询展商产品反馈留言列表
     */
    @SaCheckPermission("xhlj:productFeedback:list")
    @GetMapping("/list")
    public TableDataInfo<XhljProductFeedbackVo> list(XhljProductFeedbackQuery query, PageQuery pageQuery) {
         return xhljProductFeedbackService.queryPageList(query, pageQuery);
    }

    /**
     * 查询展商产品反馈留言列表
     */
    @SaCheckPermission("xhlj:productFeedback:list")
    @GetMapping("/allList")
    public TableDataInfo<XhljProductFeedbackVo> allList(XhljProductFeedbackQuery query) {
        List<XhljProductFeedbackVo> list =  xhljProductFeedbackService.queryList(query);
        return TableDataInfo.build(list);
    }


    /**
     * 导出展商产品反馈留言列表
     */
    @SaCheckPermission("xhlj:productFeedback:export")
    @Log(title = "展商产品反馈留言", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(XhljProductFeedbackQuery query, HttpServletResponse response) {
        List<XhljProductFeedbackVo> list = xhljProductFeedbackService.queryList(query);
        ExcelUtil.exportExcel(list, "展商产品反馈留言", XhljProductFeedbackVo.class, response);
    }

    /**
     * 获取展商产品反馈留言详细信息
     *
     * @param feedbackId 主键
     */
    @SaCheckPermission("xhlj:productFeedback:query")
    @GetMapping("/{feedbackId}")
    public R<XhljProductFeedbackVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Integer feedbackId) {
        return R.ok(xhljProductFeedbackService.queryById(feedbackId));
    }

    /**
     * 新增展商产品反馈留言
     */
    @SaCheckPermission("xhlj:productFeedback:add")
    @Log(title = "展商产品反馈留言", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody XhljProductFeedbackBo bo) {
        return toAjax(xhljProductFeedbackService.insertByBo(bo));
    }

    /**
     * 修改展商产品反馈留言
     */
    @SaCheckPermission("xhlj:productFeedback:edit")
    @Log(title = "展商产品反馈留言", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody XhljProductFeedbackBo bo) {
        return toAjax(xhljProductFeedbackService.updateByBo(bo));
    }

    /**
     * 删除展商产品反馈留言
     *
     * @param feedbackIds 主键串
     */
    @SaCheckPermission("xhlj:productFeedback:remove")
    @Log(title = "展商产品反馈留言", businessType = BusinessType.DELETE)
    @DeleteMapping("/{feedbackIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Integer[] feedbackIds) {
        return toAjax(xhljProductFeedbackService.deleteWithValidByIds(List.of(feedbackIds), true));
    }
}
